package com.home.demo.controller;

import com.home.demo.common.R;
import com.home.demo.entity.ChatHistoryEntity;
import com.home.demo.entity.dto.chat.ChatDTO;
import com.home.demo.entity.vo.chatHistory.ChatHistoryAndUserInfoVO;
import com.home.demo.service.ChatHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * 
 * 床位信息维护Controller
 */
@RestController
@RequestMapping("/chatHistory")
public class ChatHistoryController {
    @Autowired
    private ChatHistoryService chatHistoryService;

    /**
     *
     * 查询聊天记录
     * @param uid
     * @param pid
     * @return
     */
   @GetMapping("getList")
   public R getList(ChatDTO chatDTO){
       List<ChatHistoryEntity> chatHistoryEntity  = chatHistoryService.getList(chatDTO.getUid(),chatDTO.getPid());
       return R.ok().put("data",chatHistoryEntity);
   }

    /**
     * 获取通信用户聊表
     */
    @GetMapping("getSocketList")
    public R getSocketList(){
        Set<ChatHistoryAndUserInfoVO> set = new HashSet<>(chatHistoryService.getSocketList());
       return R.ok().put("data",set);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		ChatHistoryEntity bed = chatHistoryService.getById(id);

        return R.ok().put("data", bed);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ChatHistoryEntity bed){
        chatHistoryService.save(bed);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ChatHistoryEntity bed){
        chatHistoryService.updateById(bed);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
      chatHistoryService.removeByIds(Arrays.asList(ids));
      return R.ok();
    }

}
